<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="村(社区)" prop="village">
        <el-input v-model="queryParams.village" placeholder="请输入地区" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="男方姓名" prop="manName">
        <el-input v-model="queryParams.manName" placeholder="请输入男方姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="男方手机号" prop="manPhone">
        <el-input v-model="queryParams.manPhone" placeholder="请输入男方手机号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="女方姓名" prop="womanName">
        <el-input v-model="queryParams.womanName" placeholder="请输入女方姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="女方手机号" prop="womanPhone">
        <el-input v-model="queryParams.womanPhone" placeholder="请输入女方手机号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="时间" prop="affairTime">
        <el-date-picker v-model="date" type="datetimerange" align="right" unlink-panels range-separator="至"
          start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="redaffairList" @selection-change="handleSelectionChange">
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:redaffair:edit']">查看</el-button>
          <!--  <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['system:redaffair:remove']">删除</el-button> -->
        </template>
      </el-table-column>
      <el-table-column label="申报人" align="center" prop="userName" />
      <el-table-column label="村(社区)" align="center" prop="village" />
      <el-table-column label="详细地址" align="center" prop="address" />
      <el-table-column label="男方姓名" align="center" prop="manName" />
      <el-table-column label="男方手机号" align="center" prop="manPhone" width="120" />
      <el-table-column label="女方姓名" align="center" prop="womanName" />
      <el-table-column label="女方手机号" align="center" prop="womanPhone" width="120" />
      <el-table-column label="时间" align="center" prop="affairTime" width="200" />
      <el-table-column label="办理地点" align="center" prop="affairPlace" />
      <el-table-column label="场地名称" align="center" prop="affairPlaceName" />
      <el-table-column label="宴请人数" align="center" prop="peopleNum" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="200" />

    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改红事对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <div class='detail-wrapper'>
        <el-form :model="form" class="item one" :rules="rules" label-width="120px">
          <el-form-item label="申报人" prop="userName">
            <div>{{form.userName}}</div>
          </el-form-item>
          <el-form-item label="村(社区)" prop="village">
            <div>{{form.village}}</div>
          </el-form-item>
          <el-form-item label="详细地址" prop="village">
            <div>{{form.address}}</div>
          </el-form-item>
          <el-form-item label="男方姓名" prop="manName">
            <div>{{form.manName}}</div>
          </el-form-item>
          <el-form-item label="男方手机号" prop="manPhone">
            <div>{{form.manPhone}}</div>
          </el-form-item>
          <el-form-item label="政治面貌" prop="manPoliticalOutlook">
            <div>{{form.manPoliticalOutlook}}</div>
          </el-form-item>
          <el-form-item label="工作单位" prop="manWork">
            <div>{{form.manWork}}</div>
          </el-form-item>
          <el-form-item label="女方姓名" prop="womanName">
            <div>{{form.womanName}}</div>
          </el-form-item>
          <el-form-item label="女方手机号" prop="womanPhone">
            <div>{{form.womanPhone}}</div>
          </el-form-item>
          <el-form-item label="政治面貌" prop="womanPoliticalOutlook">
            <div>{{form.womanPoliticalOutlook}}</div>
          </el-form-item>
          <el-form-item label="工作单位" prop="womanWork">
            <div>{{form.womanWork}}</div>
          </el-form-item>
        </el-form>
        <el-form :model="form" class="item one" :rules="rules" label-width="100px">
          <el-form-item label="时间" prop="affairTime">
            <div>{{form.affairTime}}</div>
          </el-form-item>
          <el-form-item label="办理地点" prop="affairPlace">
            <div>{{form.affairPlace}}</div>
          </el-form-item>
          <el-form-item label="场地名称" prop="affairPlaceName">
            <div>{{form.affairPlaceName}}</div>
          </el-form-item>
          <el-form-item label="宴请人数" prop="peopleNum">
            <div>{{form.peopleNum}}</div>
          </el-form-item>
          <el-form-item label="车辆数" prop="car">
            <div>{{form.car}}</div>
          </el-form-item>
          <el-form-item label="车辆来源" prop="carSource">
            <div>{{form.carSource}}</div>
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <div>{{form.remark}}</div>
          </el-form-item>
        </el-form>
        <el-form :model="form" class="item two" label-position="top">
          <el-form-item label="是否包含外地返回人员" prop="outlander">
            <div>{{form.outlander=='1'?'是':'否'}}</div>
          </el-form-item>
          <el-form-item v-if="form.outlander=='1'" label="外来人员数" prop="outlanderNum">
            <div>{{form.outlanderNum}}</div>
          </el-form-item>
          <el-form-item label="是否来自高风险地区" prop="highRisk">
            <div>{{form.highRisk=='1'?'是':'否'}}</div>
          </el-form-item>
          <el-form-item v-if="form.highRisk=='1'" label="高风险地区" prop="highRiskPlace">
            <div>{{form.highRiskPlace}}</div>
          </el-form-item>
          <el-form-item label="是否邀请健康码为红、黄码或有发热、干咳、咽痛、乏力、腹泻" prop="abnormalMan">
            <div>{{form.abnormalMan=='1'?'是':'否'}}</div>
          </el-form-item>
          <el-form-item v-if="form.abnormalMan=='1'" label="异常症状者" prop="abnormalManName">
            <div>{{form.abnormalManName}}</div>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listRedaffair,
    getRedaffair,
    delRedaffair,
    addRedaffair,
    updateRedaffair
  } from "@/api/system/redaffair";

  export default {
    name: "Redaffair",
    data() {
      return {
        date: null,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 红事表格数据
        redaffairList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          userName: null,
          village: null,
          manName: null,
          manPhone: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
      }
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询红事列表 */
      getList() {
        this.loading = true;
        listRedaffair(this.queryParams).then(response => {
          this.redaffairList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          userName: null,
          village: null,
          manName: null,
          manPhone: null,
          manSex: null,
          manPoliticalOutlook: null,
          manWork: null,
          womanName: null,
          womanPhone: null,
          womanSex: null,
          womanPoliticalOutlook: null,
          womanWork: null,
          affairTime: null,
          affairPlace: null,
          affairPlaceName: null,
          peopleNum: null,
          car: null,
          carSource: null,
          remark: null,
          outlander: null,
          outlanderNum: null,
          highRisk: null,
          highRiskPlace: null,
          abnormalMan: null,
          abnormalManName: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;

        let params = {
          begin: this.date ? new Date(this.date[0]).getTime() : '',
          end: this.date ? new Date(this.date[1]).getTime() : '',
        }
        this.queryParams = {
          ...this.queryParams,
          ...params,
        }
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.date = null
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加红事";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getRedaffair(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "查看";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateRedaffair(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addRedaffair(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除红事编号为"' + ids + '"的数据项？').then(function() {
          return delRedaffair(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/redaffair/export', {
          ...this.queryParams
        }, `redaffair_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
<style type="text/css" lang="scss">
  .detail-wrapper {
    display: flex;

    .item {
      flex: 1;
      padding: 0 24px;
    }

    .one {
      border-right: 1px solid #eeeeee;
    }
  }
</style>
